{
 "metadata": {
  "name": "",
  "signature": "sha256:2360184c5183480d9a2f8ce3f73ed3c929a0ada3429ecb95ee828fa9ae5e98a8"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Gaussian Mixture Models and Expectation Maximisation in Shogun"
     ]
    },
    {
     "cell_type": "heading",
     "level": 4,
     "metadata": {},
     "source": [
      "By Heiko Strathmann - <a href=\"mailto:heiko.strathmann@gmail.com\">heiko.strathmann@gmail.com</a> - <a href=\"github.com/karlnapf\">github.com/karlnapf</a> - <a href=\"herrstrathmann.de\">herrstrathmann.de</a>.\n",
      "\n",
      "\n",
      "Based on the GMM framework of the <a href=\"https://www.google-melange.com/gsoc/project/google/gsoc2011/alesis_novik/11001\">Google summer of code 2011 project</a> of Alesis Novik - <a href=\"https://github.com/alesis\">https://github.com/alesis</a>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "This notebook is about learning and using Gaussian <a href=\"https://en.wikipedia.org/wiki/Mixture_model\">Mixture Models</a> (GMM) in Shogun. Below, we demonstrate how to use them for sampling, for density estimation via <a href=\"https://en.wikipedia.org/wiki/Expectation-maximization_algorithm\">Expectation Maximisation (EM)</a>, and for <a href=\"https://en.wikipedia.org/wiki/Data_clustering\">clustering</a>."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Note that Shogun's interfaces for mixture models are deprecated and are soon to be replace by more intuitive and efficient ones. This notebook contains some python magic at some places to compensate for this. However, all computations are done within Shogun itself."
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Finite Mixture Models (skip if you just want code examples)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We begin by giving some intuition about mixture models. Consider an unobserved (or latent) discrete random variable taking $k$ states $s$ with probabilities $\\text{Pr}(s=i)=\\pi_i$ for $1\\leq i \\leq k$, and $k$ random variables $x_i|s_i$ with arbritary densities or distributions, which are  *conditionally independent* of each other given the state of $s$. In the finite mixture model, we model the probability or density for a single point $x$ begin generated by the weighted mixture of the $x_i|s_i$\n",
      "\n",
      "$$\n",
      "p(x)=\\sum_{i=1}^k\\text{Pr}(s=i)p(x)=\\sum_{i=1}^k \\pi_i p(x|s)\n",
      "$$\n",
      "\n",
      "which is simply the marginalisation over the latent variable $s$. Note that $\\sum_{i=1}^k\\pi_i=1$.\n",
      "\n",
      "For example, for the Gaussian mixture model (GMM), we get (adding a collection of parameters $\\theta:=\\{\\boldsymbol{\\mu}_i, \\Sigma_i\\}_{i=1}^k$ that contains $k$ mean and covariance parameters of single Gaussian distributions)\n",
      "\n",
      "$$\n",
      "p(x|\\theta)=\\sum_{i=1}^k \\pi_i \\mathcal{N}(\\boldsymbol{\\mu}_i,\\Sigma_i)\n",
      "$$\n",
      "\n",
      "Note that *any* set of probability distributions on the same domain can be combined to such a mixture model. Note again that $s$ is an unobserved discrete random variable, i.e. we model data being generated from some weighted combination of baseline distributions. Interesting problems now are\n",
      "\n",
      " * Learning the weights $\\text{Pr}(s=i)=\\pi_i$ from data\n",
      " * Learning the parameters $\\theta$ from data for a fixed family of $x_i|s_i$, for example for the GMM\n",
      " * Using the learned model (which is a density estimate) for clustering or classification\n",
      " \n",
      "All of these problems are in the context of *unsupervised learning* since the algorithm only sees the plain data and no information on its structure."
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Expectation Maximisation"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      " <a href=\"https://en.wikipedia.org/wiki/Expectation-maximization_algorithm\">Expectation Maximisation (EM)</a> is a powerful method to learn any form of latent models and can be applied to the Gaussian mixture model case. Standard methods such as Maximum Likelihood are not straightforward for latent models in general, while EM can almost always be applied. However, it might converge to local optima and does not guarantee globally optimal solutions (this can be dealt with with some tricks as we will see later). While the general idea in EM stays the same for all models it can be used on, the individual steps depend on the particular model that is being used.\n",
      "\n",
      "The basic idea in EM is to maximise a lower bound, typically called the *free energy*, on the log-likelihood of the model. It does so by repeatedly performing two steps\n",
      "\n",
      " * The E-step optimises the free energy with respect to the latent variables $s_i$, holding the parameters $\\theta$ fixed. This is done via setting the distribution over $s$ to the posterior given the used observations.\n",
      " * The M-step optimises the free energy with respect to the paramters $\\theta$, holding the distribution over the $s_i$ fixed. This is done via maximum likelihood.\n",
      " \n",
      "It can be shown that this procedure never decreases the likelihood and that stationary points (i.e. neither E-step nor M-step produce changes) of it corresponds to local maxima in the model's likelihood. See references for more details on the procedure, and how to obtain a lower bound on the log-likelihood. There exist many different flavours of EM, including variants where only subsets of the model are iterated over at a time. There is no learning rate such as step size or similar, which is good and bad since convergence can be slow."
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Mixtures of Gaussians in Shogun"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The main class for GMM in Shogun is <a href=\"http://www.shogun-toolbox.org/doc/en/latest/classshogun_1_1CGMM.html\">CGMM</a>, which contains an interface for setting up a model and sampling from it, but also to learn the model (the $\\pi_i$ and parameters $\\theta$) via EM. It inherits from the base class for distributions in Shogun, <a href=\"http://www.shogun-toolbox.org/doc/en/latest/classshogun_1_1CDistribution.html\">CDistribution</a>,   and combines multiple single distribution instances to a mixture.\n",
      "\n",
      "We start by creating a GMM instance, sampling from it, and computing the log-likelihood of the model for some points, and the log-likelihood of each individual component for some points. All these things are done in two dimensions to be able to plot them, but they generalise to higher (or lower) dimensions easily.\n",
      "\n",
      "Let's sample, and illustrate the difference of knowing the latent variable indicating the component or not."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "%pylab inline\n",
      "%matplotlib inline\n",
      "# import all Shogun classes\n",
      "from modshogun import *"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from matplotlib.patches import Ellipse\n",
      "\n",
      "# a tool for visualisation\n",
      "def get_gaussian_ellipse_artist(mean, cov, nstd=1.96, color=\"red\", linewidth=3):\n",
      "    \"\"\"\n",
      "    Returns an ellipse artist for nstd times the standard deviation of this\n",
      "    Gaussian, specified by mean and covariance\n",
      "    \"\"\"\n",
      "    # compute eigenvalues (ordered)\n",
      "    vals, vecs = eigh(cov)\n",
      "    order = vals.argsort()[::-1]\n",
      "    vals, vecs = vals[order], vecs[:, order]\n",
      "    \n",
      "    theta = numpy.degrees(arctan2(*vecs[:, 0][::-1]))\n",
      "\n",
      "    # width and height are \"full\" widths, not radius\n",
      "    width, height = 2 * nstd * sqrt(vals)\n",
      "    e = Ellipse(xy=mean, width=width, height=height, angle=theta, \\\n",
      "               edgecolor=color, fill=False, linewidth=linewidth)\n",
      "    \n",
      "    return e"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Set up the model in Shogun"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# create mixture of three Gaussians\n",
      "num_components=3\n",
      "num_max_samples=100\n",
      "gmm=GMM(num_components)\n",
      "\n",
      "dimension=2\n",
      "\n",
      "# set means (TODO interface should be to construct mixture from individuals with set parameters)\n",
      "means=zeros((num_components, dimension))\n",
      "means[0]=[-5.0, -4.0]\n",
      "means[1]=[7.0, 3.0]\n",
      "means[2]=[0, 0.]\n",
      "[gmm.set_nth_mean(means[i], i) for i in range(num_components)]\n",
      "\n",
      "# set covariances\n",
      "covs=zeros((num_components, dimension, dimension))\n",
      "covs[0]=array([[2, 1.3],[.6, 3]])\n",
      "covs[1]=array([[1.3, -0.8],[-0.8, 1.3]])\n",
      "covs[2]=array([[2.5, .8],[0.8, 2.5]])\n",
      "[gmm.set_nth_cov(covs[i],i) for i in range(num_components)]\n",
      "\n",
      "# set mixture coefficients, these have to sum to one (TODO these should be initialised automatically)\n",
      "weights=array([0.5, 0.3, 0.2])\n",
      "gmm.set_coef(weights)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Sampling from mixture models"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Sampling is extremely easy since every instance of the <a href=\"http://www.shogun-toolbox.org/doc/en/latest/classshogun_1_1CDistribution.html\">CDistribution</a> class in Shogun allows to sample from it (if implemented)"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# now sample from each component seperately first, the from the joint model\n",
      "hold(True)\n",
      "colors=[\"red\", \"green\", \"blue\"]\n",
      "for i in range(num_components):\n",
      "    # draw a number of samples from current component and plot\n",
      "    num_samples=int(rand()*num_max_samples)+1\n",
      "    \n",
      "    # emulate sampling from one component (TODO fix interface of GMM to handle this)\n",
      "    w=zeros(num_components)\n",
      "    w[i]=1.\n",
      "    gmm.set_coef(w)\n",
      "    \n",
      "    # sample and plot (TODO fix interface to have loop within)\n",
      "    X=array([gmm.sample() for _ in range(num_samples)])\n",
      "    plot(X[:,0], X[:,1], \"o\", color=colors[i])\n",
      "    \n",
      "    # draw 95% elipsoid for current component\n",
      "    gca().add_artist(get_gaussian_ellipse_artist(means[i], covs[i], color=colors[i]))\n",
      "    \n",
      "hold(False)\n",
      "_=title(\"%dD Gaussian Mixture Model with %d components\" % (dimension, num_components))\n",
      " \n",
      "# since we used a hack to sample from each component\n",
      "gmm.set_coef(weights)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Evaluating densities in mixture Models"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Next, let us visualise the density of the joint model (which is a convex sum of the densities of the individual distributions). Note the similarity between the calls since all distributions implement the <a href=\"http://www.shogun-toolbox.org/doc/en/latest/classshogun_1_1CDistribution.html\">CDistribution</a> interface, including the mixture."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# generate a grid over the full space and evaluate components PDF\n",
      "resolution=100\n",
      "Xs=linspace(-10,10, resolution)\n",
      "Ys=linspace(-8,6, resolution)\n",
      "pairs=asarray([(x,y) for x in Xs for y in Ys])\n",
      "D=asarray([gmm.cluster(pairs[i])[3] for i in range(len(pairs))]).reshape(resolution,resolution)\n",
      "\n",
      "figure(figsize=(18,5))\n",
      "subplot(1,2,1)\n",
      "pcolor(Xs,Ys,D)\n",
      "xlim([-10,10])\n",
      "ylim([-8,6])\n",
      "title(\"Log-Likelihood of GMM\")\n",
      "\n",
      "subplot(1,2,2)\n",
      "pcolor(Xs,Ys,exp(D))\n",
      "xlim([-10,10])\n",
      "ylim([-8,6])\n",
      "_=title(\"Likelihood of GMM\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Density estimating with mixture models"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Now let us draw samples from the mixture model itself rather than from individual components. This is the situation that usually occurs in practice: Someone gives you a bunch of data with no labels attached to it all all. Our job is now to find structure in the data, which we will do with a GMM."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# sample and plot (TODO fix interface to have loop within)\n",
      "X=array([gmm.sample() for _ in range(num_max_samples)])\n",
      "plot(X[:,0], X[:,1], \"o\")\n",
      "_=title(\"Samples from GMM\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Imagine you did not know the true generating process of this data. What would you think just looking at it? There are clearly at least two components (or clusters) that might have generated this data, but three also looks reasonable. So let us try to learn a Gaussian mixture model on those."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def estimate_gmm(X, num_components):\n",
      "    # bring data into shogun representation (note that Shogun data is in column vector form, so transpose)\n",
      "    features=RealFeatures(X.T)\n",
      "    \n",
      "    gmm_est=GMM(num_components)\n",
      "    gmm_est.set_features(features)\n",
      "    \n",
      "    # learn GMM\n",
      "    gmm_est.train_em()\n",
      "    \n",
      "    return gmm_est"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "So far so good, now lets plot the density of this GMM using the code from above"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "component_numbers=[2,3]\n",
      "\n",
      "# plot true likelihood\n",
      "D_true=asarray([gmm.cluster(pairs[i])[num_components] for i in range(len(pairs))]).reshape(resolution,resolution)\n",
      "figure(figsize=(18,5))\n",
      "subplot(1,len(component_numbers)+1,1)\n",
      "pcolor(Xs,Ys,exp(D_true))\n",
      "xlim([-10,10])\n",
      "ylim([-8,6])\n",
      "title(\"True likelihood\")\n",
      "\n",
      "for n in range(len(component_numbers)):\n",
      "    # TODO get rid of these hacks and offer nice interface from Shogun\n",
      "    \n",
      "    # learn GMM with EM\n",
      "    gmm_est=estimate_gmm(X, component_numbers[n])\n",
      "    \n",
      "    # evaluate at a grid of points\n",
      "    D_est=asarray([gmm_est.cluster(pairs[i])[component_numbers[n]] for i in range(len(pairs))]).reshape(resolution,resolution)\n",
      "    \n",
      "    # visualise densities\n",
      "    subplot(1,len(component_numbers)+1,n+2)\n",
      "    pcolor(Xs,Ys,exp(D_est))\n",
      "    xlim([-10,10])\n",
      "    ylim([-8,6])\n",
      "    _=title(\"Estimated likelihood for EM with %d components\"%component_numbers[n])"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "It is also possible to access the individual components of the mixture distribution. In our case, we can for example draw 95% ellipses for each of the Gaussians using the method from above. We will do this (and more) below."
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "On local minima of EM"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "It seems that three comonents give a density that is closest to the original one. While two components also do a reasonable job here, it might sometimes happen (<a href=\"http://www.shogun-toolbox.org/doc/en/latest/classshogun_1_1CKMeans.html\">KMeans</a> is used to initialise the cluster centres if not done by hand, using a random cluster initialisation) that the upper two Gaussians are grouped, re-run for a couple of times to see this. This illustrates how EM might get stuck in a local minimum. We will do this below, where it might well happen that all runs produce the same or different results - no guarantees.\n",
      "Note that it is easily possible to initialise EM via specifying the parameters of the mixture components as did to create the original model above.\n",
      "\n",
      "One way to decide which of multiple convergenced EM instances to use is to simply compute many of them (with different initialisations) and then choose the one with the largest likelihood. *WARNING* Do not select the number of components like this as the model will overfit."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# function to draw ellipses for all components of a GMM\n",
      "def visualise_gmm(gmm, color=\"blue\"):\n",
      "\n",
      "    for i in range(gmm.get_num_components()):\n",
      "        component=Gaussian.obtain_from_generic(gmm.get_component(i))\n",
      "        gca().add_artist(get_gaussian_ellipse_artist(component.get_mean(), component.get_cov(), color=color))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# multiple runs to illustrate random initialisation matters\n",
      "for _ in range(3):\n",
      "    figure(figsize=(18,5))\n",
      "    \n",
      "    subplot(1, len(component_numbers)+1, 0)\n",
      "    plot(X[:,0],X[:,1], 'o')\n",
      "    visualise_gmm(gmm_est, color=\"blue\")\n",
      "    title(\"True components\")\n",
      "    \n",
      "    for i in range(len(component_numbers)):\n",
      "        gmm_est=estimate_gmm(X, component_numbers[i])\n",
      "        \n",
      "        subplot(1, len(component_numbers)+1, i+1)\n",
      "        plot(X[:,0],X[:,1], 'o')\n",
      "        visualise_gmm(gmm_est, color=colors[i])\n",
      "        \n",
      "        # TODO add a method to get likelihood of full model, retraining is inefficient\n",
      "        likelihood=gmm_est.train_em()\n",
      "        _=title(\"Estimated likelihood: %.2f (%d components)\"%(likelihood,component_numbers[i]))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Clustering with mixture models"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Recall that our initial goal was not to visualise mixture models (although that is already pretty cool) but to find clusters in a given set of points. All we need to do for this is to evaluate the log-likelihood of every point under every learned component and then pick the largest one. Shogun can do both. Below, we will illustrate both cases, obtaining a cluster index, and evaluating the log-likelihood for every point under each component."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def cluster_and_visualise(gmm_est):\n",
      "    # obtain cluster index for each point of the training data\n",
      "    # TODO another hack here: Shogun should allow to pass multiple points and only return the index\n",
      "    # as the likelihood can be done via the individual components\n",
      "    # In addition, argmax should be computed for us, although log-pdf for all components should also be possible\n",
      "    clusters=asarray([argmax(gmm_est.cluster(x)[:gmm.get_num_components()]) for x in X])\n",
      "    \n",
      "    # visualise points by cluster\n",
      "    hold(True)\n",
      "    for i in range(gmm.get_num_components()):\n",
      "        indices=clusters==i\n",
      "        plot(X[indices,0],X[indices,1], 'o', color=colors[i])\n",
      "        \n",
      "    hold(False)\n",
      "\n",
      "# learn gmm again\n",
      "gmm_est=estimate_gmm(X, num_components)\n",
      "    \n",
      "figure(figsize=(18,5))\n",
      "subplot(121)\n",
      "cluster_and_visualise(gmm)\n",
      "title(\"Clustering under true GMM\")\n",
      "subplot(122)\n",
      "cluster_and_visualise(gmm_est)\n",
      "_=title(\"Clustering under estimated GMM\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "These are clusterings obtained via the true mixture model and the one learned via EM. There is a slight subtlety here: even the model under which the data was generated will not cluster the data correctly if the data is overlapping. This is due to the fact that the cluster with the largest probability is chosen. This doesn't allow for any ambiguity. If you are interested in cases where data overlaps, you should always look at the log-likelihood of the point for each cluster and consider taking into acount \"draws\" in the decision, i.e. probabilities for two different clusters are equally large.\n",
      "\n",
      "Below we plot all points, coloured by their likelihood under each component."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "figure(figsize=(18,5))\n",
      "\n",
      "for comp_idx in range(num_components):\n",
      "    subplot(1,num_components,comp_idx+1)\n",
      "    \n",
      "    # evaluated likelihood under current component\n",
      "    # TODO Shogun should do the loop and allow to specify component indices to evaluate pdf for\n",
      "    # TODO distribution interface should be the same everywhere\n",
      "    component=Gaussian.obtain_from_generic(gmm.get_component(comp_idx))\n",
      "    cluster_likelihoods=asarray([component.compute_PDF(X[i]) for i in range(len(X))])\n",
      "    \n",
      "    # normalise\n",
      "    cluster_likelihoods-=cluster_likelihoods.min()\n",
      "    cluster_likelihoods/=cluster_likelihoods.max()\n",
      "    \n",
      "    # plot, coloured by likelihood value\n",
      "    cm=get_cmap(\"jet\")\n",
      "    hold(True)\n",
      "    for j in range(len(X)):\n",
      "        color = cm(cluster_likelihoods[j])\n",
      "        plot(X[j,0], X[j,1]  ,\"o\", color=color) \n",
      "    hold(False)\n",
      "    title(\"Data coloured by likelihood for component %d\" % comp_idx)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Note how the lower left and middle cluster are overlapping in the sense that points at their intersection have similar likelihoods. If you do not care at all about this and are just interested in a partitioning of the space, simply choose the maximum. \n",
      "\n",
      "Below we plot the space partitioning for a hard clustering."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# compute cluster index for every point in space\n",
      "D_est=asarray([gmm_est.cluster(pairs[i])[:num_components].argmax() for i in range(len(pairs))]).reshape(resolution,resolution)\n",
      "\n",
      "# visualise clustering\n",
      "cluster_and_visualise(gmm_est)\n",
      "\n",
      "# visualise space partitioning\n",
      "hold(True)\n",
      "pcolor(Xs,Ys,D_est)\n",
      "hold(False)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Coming soon"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      " * Split and merge Expectation Maximisation\n",
      "\n",
      "TODO (bugfixes, interface issues, see also all the TODOs in notebook)\n",
      "\n",
      " * Check cholesky computation\n",
      " * likelhoods should sum to one\n",
      " * sample multiple points\n",
      " * rename cluster method to compute_log_likelihoods\n",
      " * pull model likelihood out of sample\n",
      " * proper mixture model interface with classical distribution and EM interface (E,M methods)\n",
      " \n",
      " * set_coef dimensiosn check. DImension check in general\n",
      " * check for initialization before sampling\n",
      " * eigen3ize Gaussian and remove GaussianDistribution\n",
      " \n",
      "\n",
      " "
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "References"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "[1]: Barber, D. (2012). Bayesian Reasoning and Machine Learning. Cambridge University Press.\n",
      "\n",
      "[2]: Bishop, C. M., & others. (2006). Pattern recognition and machine learning. Springer New York.\n",
      "\n",
      "[3]: Gatsby Computational Neurocience Unit lecture notes for Machine Learning <a href=\"http://www.gatsby.ucl.ac.uk/teaching/courses/ml1-2013.html\">(link)</a>\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}
